using System.Security.Cryptography;
using System.Text;

namespace CoreProject.Api
{
    public class MD5Helper
    {
        /// <summary>
        /// Md5加密，返回32位的字符串
        /// </summary>
        /// <param name="input"></param>
        /// <param name="type">返回值大小写，默认x2，小写，大写是X2</param>
        /// <returns></returns>
        public static string Md5(string input, string type = "x2")
        {
            MD5 md5 = MD5.Create();

            byte[] bytes = Encoding.Default.GetBytes(input);

            byte[] bytesMd5 = md5.ComputeHash(bytes);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < bytesMd5.Length; i++)
            {
                sb.Append(bytesMd5[i].ToString(type));
            }

            return sb.ToString();
        }
    }
}
